package edu.ynmd.bmi.action;

import edu.ynmd.bmi.vo.BMIForm;
import edu.ynmd.bmi.vo.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PublicAction {
    @PostMapping("getBMIValue")
    public Result getBMIValue(@RequestBody BMIForm bmiForm) throws Exception{
        Float resultf=bmiForm.getTg()/(bmiForm.getSg()*bmiForm.getSg());

        String resultstr="";

        if (resultf<=18.4){
            resultstr="偏瘦";
        }
        else if(resultf>=18.5&&resultf<=23.9){
            resultstr="正常";
        }
        else if(resultf>=24&&resultf<=27.9){
            resultstr="微胖";
        }
        else {
            resultstr="肥胖";
        }

        Result r=new Result();

        r.setState(resultstr);
        r.setValue(resultf);

        switch (resultstr){
            case "偏瘦":
            r.setSugguest("多吃点");
            break;
            case "正常":
                r.setSugguest("不要多吃，也别少吃");
                break;
            case "微胖":
                r.setSugguest("少吃点");
                break;
            case "肥胖":
                r.setSugguest("绝食");
                break;
        }

        return r;


    }

}
